var API = require('API');
module.exports = function(){
    return {
        restrict: 'AE',
        scope:{
            user:'=',
            data:'=ngModel',
            del:'&',
            mode:'='
        },
        templateUrl:'/modules/admin/users/users.inc.html',
        replace: true,
        controller: ['$scope','$timeout', function($scope,$timeout){

            $scope.user = $scope.user || {};
            $scope.data = $scope.data || [];


            // 选择用户
            $scope.selected_user = function(item){
                API.user.get(item.uid, function (u) {
                    $scope.$apply(function(){
                        $scope.user = u;    
                    })
                })
                
                if (item.iscolor) {
                    item.iscolor = false;
                } else {
                    for (var i = 0; i < $scope.data.length; i++) {
                        $scope.data[i].iscolor = false;
                    }
                    item.iscolor = true;
                }
            };

        }]
    }
};